package data

import (
	"061/Sgame/server/game/model"
	"time"
)

//军队
type Skill struct {
	Id             int       `gorm:"column:id;primaryKey"`
	RId            int       `gorm:"column:rid"`
	CfgId          int       `gorm:"column:cfgId;comment:技能id"`
	BelongGenerals string    `gorm:"column:belong_generals;comment:归属武将数组"`
	CTime          time.Time `gorm:"column:ctime;comment:获得技能时间"`
	Generals       []int     `gorm:"-"`
}

func (s *Skill) TableName() string {
	return "skill"
}

//func (a *Skill) AfterSet(name string, cell gorm.Cell){
//	//[0,0,0]
//	if name == "belong_generals"{
//		a.Generals = make([]int,0)
//		if cell != nil{
//			gs, ok := (*cell).([]uint8)
//			if ok {
//				json.Unmarshal(gs, &a.Generals)
//				fmt.Println(a.Generals)
//			}
//		}
//	}
//}

func NewSkill(rid int, cfgId int) *Skill {
	return &Skill{
		CfgId:          cfgId,
		RId:            rid,
		Generals:       []int{},
		BelongGenerals: "[]",
	}
}

func (s *Skill) ToModel() interface{} {
	p := model.Skill{}
	p.Id = s.Id
	p.CfgId = s.CfgId
	p.Generals = s.Generals
	return p
}
